using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using WpfWordsLearner.Helper;
using System.Windows;

namespace WpfWordsLearner.ViewModels
{
	public class AddWordListViewModel : BaseViewModel
	{
		public AddWordListViewModel()
		{
			WordList = new List<Model.WordsModel>();
		}

		private List<Model.WordsModel> m_list = null;
		public ICommand AddCommand { get { return new BaseCommand(Click); } }

		private void Click()
		{
			if (WordsManager.Instance.AddWordRange(WordList))
				ShowMessageBox(WpfWordsLearner.Properties.Resources.msgWordAdded);
			else
				ShowMessageBoxError(WpfWordsLearner.Properties.Resources.msgFailAddWord);

			Window wind = App.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
			if (wind != null)
			{
				wind.DialogResult = true;
				wind.Close();
			}
		}

		public ICommand CancelCommand { get { return new BaseCommand(Click2); } }
		private void Click2()
		{
			Window wind = App.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
			if (wind != null)
			{
				wind.DialogResult = false;
				wind.Close();
			}
		}

		public List<Model.WordsModel> WordList
		{
			get { return m_list; }
			set
			{
				m_list = value;
				OnPropertyChanged(() => WordList);
			}
		}
	}
}
